package online

import (
	"server/common"

	"github.com/mitchellh/mapstructure"
)

// -------------------------------------------------------------------------------------------------
//
// -------------------------------------------------------------------------------------------------
func (s *OnlineService) handleLoginAck(msg common.Message) {
	common.Logger(common.SERVICE_TYPE_ONLINE, msg.Rid).WithField("msg", common.ToJson(msg)).
		Info("handling login ack")

	if msg.Data == nil {
		LOG(msg.Rid).Error("login ack data is nil")
		return
	}

	var resData common.ResMsgData
	if err := mapstructure.Decode(msg.Data, &resData); err != nil {
		LOG(msg.Rid).WithError(err).Error("failed to decode login ack response data")
		return
	}

	var ackData common.LoginAckData
	if err := mapstructure.Decode(msg.Data, &ackData); err != nil {
		LOG(msg.Rid).WithError(err).Error("failed to decode login ack data")
		return
	}

	if ackData.UserId == "" {
		LOG(msg.Rid).Error("userId is empty in login ack")
		return
	}

	if resData.Code != 0 {
		LOG(msg.Rid).Error("login ack response indicates failure")
		return
	}
}
